﻿using AutoMapper;
using ProjectManageSystemApi.DbEntity;
using ProjectManageSystemApi.Models;

namespace ProjectManageSystemApi.Services.Impl
{
    public class RoleAuthServices : IRoleAuthServices
    {
        readonly IFreeSql _fsql;
        readonly IMapper _mapper;
        public RoleAuthServices(IFreeSql fsql, IMapper mapper) 
        {
            _fsql = fsql;
            _mapper = mapper;
        }
        public SysCoreRoleExtraDto GetRoleAuthById(long userId) 
        {
            var data = _fsql.Select<SysCoreRoleExtra>().Where(x=> _fsql.Select<SysCoreUserRoleLink>().Any(y => y.UserId == userId && x.RoleId == y.RoleId));
            return _mapper.Map<SysCoreRoleExtraDto>(data.ToOne());
        }
        public bool IsShowAllProject(long userId) 
        {
            return GetRoleAuthById(userId).ShowAllProject;
        }
    }
}
